import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getLoginSerive } from '@/api/login'
export const useUserStore = defineStore( 'user' , () => {
    // 登录接口
    const userInfo = ref({})
    const getUserInfo = async ({ account, password }) => {
      const res = await getLoginSerive({ account, password })
      userInfo.value = res.data.result
    }
    const token = ref('')
    // 存储token
    const setToken = (newToken) => {
      token.value = newToken
    }
    // 删除token
    const removeToken = () => {
      token.value = ''
    }
    // 清空本地数据
    const clearUserData = () => {
      userInfo.value = ref({})
      // storeCar.clearCar()
    }
    return {
      userInfo,
      getUserInfo,
      token,
      setToken,
      removeToken,
      clearUserData
    }
  },
  {
    persist: true
  }
)
